package com.example.controller;

import com.example.pojo.WorkSchedule;
import com.example.service.IWorkScheduleService;
import com.example.vo.ResultVo;
import com.example.vo.per.ClockInParams;
import com.example.vo.per.EmpTurnover;
import com.example.vo.per.WorkScheduleParams;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 排班表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/workSchedule")
@Api(tags = "排班表",value = "")
@CrossOrigin(allowCredentials = "true")
public class WorkScheduleController {

    @Autowired
    private IWorkScheduleService iwss;

    @PostMapping("")
    @ApiOperation("批量 - 新增排班人员")
    public ResultVo addListByWordId(@RequestBody WorkScheduleParams wsp){
        System.out.println("wsp ->" + wsp);
        return iwss.insByListWorkSchedule(wsp);
    }

    @GetMapping("")
    @ApiOperation("查询排班人员")
    public ResultVo getListSchedule(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize,
                                Integer datasel,
                                Integer statussel){

        List<Map<String,Object>> info = iwss.selByListWorkSchedule(datasel, statussel, pageNum, pageSize);
        if (info != null){
            return ResultVo.response(info);
        }
        return ResultVo.error();
    }

    @DeleteMapping("")
    @ApiOperation("取消排班")
    public ResultVo delSchedule(@RequestParam("rids") Integer[] workIds){
        iwss.delByworids(workIds);
        return ResultVo.ok();
    }

    @GetMapping("/date-control")
    @ApiOperation("查询排班")
    public ResultVo getDateControl(@RequestParam("wid") Integer wid,@RequestParam(value = "mon",defaultValue = "0") Integer mon){
        System.err.println("wid " +  wid);
        System.err.println("mon " +  mon);
        List<ClockInParams> list = iwss.sellistcip(wid,mon);
        if (!list.isEmpty()){
            return ResultVo.response(list);
        }
        return ResultVo.error();
    }
}
